﻿// Sheego.Service.X400
// Copyright(C) 2015 Schwab Versand GmbH
//
// This source file is subject to the Microsoft Public License(Ms-PL).
// http://www.opensource.org/licenses/ms-pl.html
// All other rights reserved.

using Sheego.Service.X400.Job.Shared.Locator;
using Sheego.Service.X400.Scheduler.Shared.Locator;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace ConsoleApplication
{
    class Program
    {
        static void Main(string[] args)
        {
            var scheduler = SchedulerLocator.GetScheduler();
            var logger = SchedulerLocator.GetSchedulerLogger();


            //Add Job to Scheduler
            var job = JobLocator.GetJob();
            job.Disabled = false;

            scheduler.Jobs.Add(job);

            // Create the thread object, passing in the Scheduler.Run method
            // via a ThreadStart delegate. This does not start the thread.
            var thread = new Thread(new ThreadStart(scheduler.Run));

            // Start the thread
            thread.Start();


            logger.Info("ConsoleApplication gestartet");


            Thread.Sleep(TimeSpan.FromMinutes(10));



            //STop the Scheduler
            scheduler.ShouldRun = false;

            // Wait until oThread finishes. Join also has overloads
            // that take a millisecond interval or a TimeSpan object.
            if (!thread.Join(TimeSpan.FromSeconds(10)))
            {
                logger.Error("Could not Stop Thread");
                thread.Abort();
            }

            thread = null;
            scheduler = null;

            logger.Info("ConsoleApplication gestoppt");
            logger = null;



        }
    }
}
